package com.lxq.LeetCode.letterCombinations;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public static void main(String[] args) {
        List<String> res = letterCombinations("22");
        System.out.println(res.size());
        System.out.println(res.toString());
    }

    public static List<String> letterCombinations(String digits) {
        String[] alphabet = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        List<String> res = new ArrayList<>();
        if (digits.length() == 0) {
            return res;
        } else {
            for (int i = 0; i < alphabet[digits.charAt(0) - '0'].length(); i++) {
                String temp1 = "";
                temp1 = "" + alphabet[digits.charAt(0) - '0'].charAt(i);
                if (digits.length() > 1) {
                    for (int j = 0; j < alphabet[digits.charAt(1) - '0'].length(); j++) {
                        String temp2 = "";
                        temp2 = "" + alphabet[digits.charAt(1) - '0'].charAt(j);
                        if (digits.length() > 2) {
                            for (int m = 0; m < alphabet[digits.charAt(2) - '0'].length(); m++) {
                                String temp3 = "";
                                temp3 = "" + alphabet[digits.charAt(2) - '0'].charAt(m);
                                if (digits.length() > 3) {
                                    for (int n = 0; n < alphabet[digits.charAt(3) - '0'].length(); n++) {
                                        String temp4 = "";
                                        temp4 = "" + alphabet[digits.charAt(3) - '0'].charAt(n);
                                        res.add(temp1 + temp2 + temp3 + temp4);
                                    }
                                } else {
                                    res.add(temp1 + temp2 + temp3);
                                }

                            }
                        } else {
                            res.add(temp1 + temp2);
                        }
                    }

                } else {
                    res.add(temp1);
                }
            }

        }

        return res;
    }
}
